/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Distribuciones;

import entidad.FactoryDistribucion.DISTRIBUCION_NOMBRES;
import java.util.Random;


/**
 *
 * @author USUARIO
 */
public class BoxMuller  implements Distribucion {
    
    public static long DEFAULT_RAIZ = 987654321L;
    private double media;
    private double varianza;
    private double x;
    private double y;
    Random random;
    public static final DISTRIBUCION_NOMBRES nombre = DISTRIBUCION_NOMBRES.NORMAL;
    public static final String[] parametros = {"media","varianza"};
    public static final String[] tipoParametros = {"double", "double"};
   
    public BoxMuller(double media, double varianza, long raiz) {
        this.media = media;
        this.varianza = varianza;
        this.random = new Random(raiz);
    }

    @Override
    public String[] getParametros() {
        return parametros;
    }

    @Override
    public String[] getTipoParametros() {
        return tipoParametros;
    }
    
    @Override
    public double generar(double u){
        double theta = u * 2 * Math.PI;
        double u2 = random.nextDouble();
        double r = Math.sqrt(-2 * Math.log(u2));
        x = r * Math.cos(theta) * Math.sqrt(varianza) + media;
        y = r * Math.sin(theta) * Math.sqrt(varianza) + media;
        return x;
    }

    public double getMedia() {
        return media;
    }

    public double getVarianza() {
        return varianza;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    @Override
    public DISTRIBUCION_NOMBRES getNombre() {
        return nombre;
    }

    @Override
    public double calcularMedia() {
        return media;
    }


}
